#include<iostream>
using namespace std;
class Date{
public:
    Date(int year, int month, int day)
        :_year(year)
        ,_month(month)
        ,_day(day)
        {}
    Date& operator+(const int days){
        //不考虑days为负
        Date temp(*this);
        temp._day += days;
        while(temp._day > GetDayOfMonth(temp._year,temp._month)){
            temp._day -= GetDayOfMonth(temp._year,temp._month);
            temp._month += 1;
            if(temp._month > 12){
                temp._month = 1;
                temp._year += 1;
            }
        }
        return temp; 
}
    bool LeadYear(const int year){
        return (!(year % 4) && (year % 100) || ( !(year % 400)));
    }
    
    int GetDayOfMonth(const int year, const int month){
        int days[] = { 0 ,31,28,31,30,31,30,31,31,30,31,30,31};
        if(LeadYear(year))
            days[2] += 1;
        return days[month];
    }
    
    Date& operator=(const Date& d){
        if(this != &d){
            _year = d._year;
            _month = d._month;
            _day = d._day;
        }
        return *this;
    }
    
    void PutDate()const{
        if(_month < 10 && _day < 10)
            cout << _year << '-' << 0 << _month << '-' << 0 << _day << endl;      
        else if(_month < 10)
            cout << _year << '-' << 0 << _month << '-' << _day << endl;
        else if(_day < 10)
            cout << _year << '-' << _month << '-' << 0 << _day << endl;         
        else
            cout << _year << '-' << _month << '-' << _day << endl;  
    }
private:
    int _year;
    int _month;
    int _day;
};
int main(){
    int m,year,month,day,days;
    cin >> m;
  while(m--){
     cin >> year >> month >> day >> days;
     Date d1(year,month,day);
     d1 = d1 + days; 
     d1.PutDate();
  }
    return 0;
}